package com.op.converter;

import com.op.constants.DifficultyConstant;
import com.op.entity.Question;
import com.op.model.vo.ExamPaperVo;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName： PaperConverter
 * Date： 2021/10/22 22:16
 *
 * @author 孤焰
 * @version 1.0
 **/

public class PaperConverter {
    /**
     * 将question列表转换成Vo类型列表
     * @param questionList 题库列表
     * @return ExamPaperVo列表
     */
    public static List<ExamPaperVo> covertQuestionToPaperVo(List<Question> questionList) {
        List<ExamPaperVo> paperList = new ArrayList<>();
        questionList.forEach(question -> {
            ExamPaperVo examPaperVo = new ExamPaperVo();
            examPaperVo.setQuestionId(question.getId());
            examPaperVo.setBankId(question.getBankId());
            examPaperVo.setProblem(question.getProblem());
            examPaperVo.setSolution(question.getSolution());
            examPaperVo.setTags(question.getTags());
            switch (question.getDifficulty()) {
                case 0: examPaperVo.setDifficulty(DifficultyConstant.UN_KNOWN);
                    break;
                case 1: examPaperVo.setDifficulty(DifficultyConstant.SIMPLE);
                    break;
                case 2: examPaperVo.setDifficulty(DifficultyConstant.MEDIUM);
                    break;
                case 3: examPaperVo.setDifficulty(DifficultyConstant.DIFFICULT);
                    break;
                default: examPaperVo.setDifficulty(DifficultyConstant.ERROR);
            }
            paperList.add(examPaperVo);
        });
        return paperList;
    }
}
